package com.elong.businesstravel.modules.home.hotel.hotelpayment;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import android.R.string;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Debug;
import android.text.InputFilter;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.edittextclear.EditTextClearView;
import com.android.support.jhf.handlerui.HandlerPostUI;
import com.android.support.jhf.handlerui.HandlerToastUI;
import com.android.support.jhf.network.NetworkClient;
import com.android.support.jhf.network.loopj.android.http.ResponseHandlerInterface;
import com.android.support.jhf.utils.AppJump;
import com.android.support.jhf.utils.ConfigManager;
import com.android.support.jhf.utils.DateUtils;
import com.android.support.jhf.utils.ValidateOperator;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.baseactivity.BaseActivity;
import com.elong.businesstravel.base.dialog.CustomAlertDialog;
import com.elong.businesstravel.base.dialog.CustomListDialog;
import com.elong.businesstravel.base.dialog.CustomListDialog.CustomListDialogItem;
import com.elong.businesstravel.base.utils.AppUserId;
import com.elong.businesstravel.base.utils.SaveUserOperate;
import com.elong.businesstravel.base.view.TitleNavBarView;
import com.elong.businesstravel.entitys.HotelDocs;
import com.elong.businesstravel.entitys.HotelPrice;
import com.elong.businesstravel.entitys.HotelPrice.BookingRuleInfo;
import com.elong.businesstravel.entitys.HotelPrice.GuaranteeRuleInfo;
import com.elong.businesstravel.entitys.HotelPrice.PrepayRuleInfo;
import com.elong.businesstravel.entitys.HotelPrice.RatePlanInfo;
import com.elong.businesstravel.entitys.SubmitOrderParam;
import com.elong.businesstravel.modules.home.hotel.dialog.ArrivalHotelDateDialog;
import com.elong.businesstravel.modules.home.hotel.dialog.BounsDescDialog;
import com.elong.businesstravel.modules.orders.OrdersActivity;
import com.elong.businesstravel.protocol.hotel.CheckGuestRequest;
import com.elong.businesstravel.protocol.hotel.CheckGuestResponse;
import com.elong.businesstravel.protocol.hotel.GuesshotelRequest;
import com.elong.businesstravel.protocol.hotel.GuesshotelResponse;
import com.elong.businesstravel.protocol.order.CreateOrderRequest;
import com.elong.businesstravel.protocol.order.CreateOrderResponse;
import com.umeng.analytics.MobclickAgent;

/**
 * 填写订单页
 * 
 * @author lenovo
 * 
 */
public class SubmitOrdersActivity extends BaseActivity {
	/** 默认最多可以定多少房间 */
	public static final int MAX_ROOM = 6;

	private ViewGroup mLiveNameLayout;
	private TextView mFangJianTextView;
	private EditTextClearView mPhoneEditTextClearView;
	private ViewGroup mModifyRetainLayout;
	private View mModifyRetainDivider;
	private TextView mRetainDateTextView;
	private TextView mMoneyTextView;
	private TextView mRuleDescriptionTextView;
	private TextView mFanTextView;
	private Button mSubmitOrderButton;
	private Button mNextButton;
	private Button mDefrayButton;
	private ImageView mSubImageView;
	private ImageView mAddImageView;

	private RatePlanInfo mRatePlanInfo;
	private HotelDocs mHotelDocs;
	/** 房间保留到,显示用 */
	private List<String> mArrayArrival = new ArrayList<String>();
	/** 房间保留到,上传数据用 */
	private List<String> mUploadArrival = new ArrayList<String>();
	/** 担保房间数量，超过这个数量需要担保 */
	private int mRoomAmount = 0;
	/** 当期选择的房间数量 */
	private int mCurrentRoomAmount = 1;
	/** 最少预订房间数量 */
	private int mMinBooking = 1;
	/** 姓名是否需要国籍 */
	private boolean mIsNeedNationality = false;
	/** 您预订了N间房，请您提供不少于N的入住客人姓名 前台判断 */
	private boolean mIsPerRoomPerName;
	private boolean mIsTimeGuarantee = false;
	private boolean mIsAmountGuarantee = false;
	/** 最晚到店时间 ,上传数据 */
	private String mLatestarrival;
	/** 最晚到店时间，显示数据用来判断 */
	private String mShowLatestarrival;
	
	private Bundle mSavedInstanceState;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_submit_orders);
		mSavedInstanceState = savedInstanceState;
		init();
	}

	@Override
	protected void init() {
		if(null == mSavedInstanceState){
		mRatePlanInfo = (RatePlanInfo) getIntent().getSerializableExtra(
				"ratePlanInfo");
		mHotelDocs = (HotelDocs) getIntent().getSerializableExtra("hotelDocs");
		}else {
		mRatePlanInfo = (RatePlanInfo) mSavedInstanceState.getSerializable(
				"ratePlanInfo");
		mHotelDocs = (HotelDocs) mSavedInstanceState.getSerializable("hotelDocs");
		}

		mRuleDescriptionTextView = (TextView) findViewById(R.id.ruleDescriptionTextView);

		setRatePlanInfo(mRatePlanInfo);

		TextView hotelNameTextView = (TextView) findViewById(R.id.hotelNameTextView);
		hotelNameTextView.setText(mHotelDocs.hotelName);

		TextView roomFlagTextView = (TextView) findViewById(R.id.roomFlagTextView);
		String roomNameString = mRatePlanInfo.RoomName;
		roomNameString = roomNameString.replace(" ", "");
		roomNameString = roomNameString.replace("（", "(");
		roomNameString = roomNameString.replace("）", ")");

		if (!"".equals(mRatePlanInfo.nrpname)) {
			roomNameString = roomNameString + "-" + mRatePlanInfo.nrpname;
		}
		roomFlagTextView.setText(roomNameString);

		mMoneyTextView = (TextView) findViewById(R.id.moneyTextView);
		setTotalPriceFloatView();

		mFanTextView = (TextView) findViewById(R.id.fanTextView);
		ViewGroup fanLayout = (ViewGroup) findViewById(R.id.fanLayout);
		if ("".equals(mRatePlanInfo.Bonus) || "0".equals(mRatePlanInfo.Bonus)) {
			fanLayout.setVisibility(View.GONE);
		} else {
			fanLayout.setVisibility(View.VISIBLE);
			mFanTextView.setText(getTotalBounsInt() + "");
		}

		TextView dateTextView = (TextView) findViewById(R.id.dateTextView);
		String start = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.getStartDate(), "yyyyMMdd"),
				"MM月dd日");
		String end = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.getEndDate(), "yyyyMMdd"),
				"MM月dd日");
		dateTextView.setText("入住 " + start + "- 离店 " + end);

		mModifyRetainLayout = (ViewGroup) findViewById(R.id.modifyRetainLayout);
		mModifyRetainDivider = findViewById(R.id.modifyRetainDivider);
		mRetainDateTextView = (TextView) findViewById(R.id.retainDateTextView);
		mRetainDateTextView.setText(mArrayArrival.get(0));

		mFangJianTextView = (TextView) findViewById(R.id.fangJianTextView);
		mFangJianTextView.setText(mCurrentRoomAmount + "间");

		TextView contactsTextView = (TextView) findViewById(R.id.contactsTextView);
		contactsTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				AppJump.goContacts((Activity) mContext, 1);
			}
		});
		mPhoneEditTextClearView = (EditTextClearView) findViewById(R.id.phoneNumberTextView);
		String livePhoneString = SaveUserOperate.getLivePhone(mContext);
		if (TextUtils.isEmpty(livePhoneString)) {
			livePhoneString = SaveUserOperate.getLoginPhone(mContext);
		}
		mPhoneEditTextClearView.getEditText().setText(livePhoneString);
		mPhoneEditTextClearView.getEditText().setSingleLine();
		mPhoneEditTextClearView.getEditText().setInputType(
				InputType.TYPE_CLASS_PHONE);
		mPhoneEditTextClearView.getEditText().setFilters(
				new InputFilter[] { new InputFilter.LengthFilter(11) });
		
		mLiveNameLayout = (ViewGroup) findViewById(R.id.liveNameLayout);
		mLiveNameLayout.removeAllViews();
		try {
			mMinBooking = Integer.parseInt(mRatePlanInfo.MinBooking);
		} catch (Exception e) {
		}
		// mMinBooking = 3;
		mCurrentRoomAmount = mMinBooking;
		for (int i = 0; i < mMinBooking; i++) {
			// 创建最少房间数
			if (0 == i) {
				mLiveNameLayout.addView(createLiveNameView(SaveUserOperate
						.getLiveName(mContext)));
			} else {
				if (mIsPerRoomPerName) {
					mLiveNameLayout.addView(createLiveNameView(""));
				}
			}
		}

		mSubmitOrderButton = (Button) findViewById(R.id.submitOrderButton);
		mNextButton = (Button) findViewById(R.id.nextButton);
		mDefrayButton = (Button) findViewById(R.id.defrayButton);

		if (mRatePlanInfo.PaymentType.equals("Prepay")) {
			// 预付。没有到店时间了
			mModifyRetainDivider.setVisibility(View.GONE);
			mModifyRetainLayout.setVisibility(View.GONE);
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.GONE);
			mDefrayButton.setVisibility(View.VISIBLE);
		} else if ((!"".equals(mRatePlanInfo.GuaranteeRuleIds) && mRatePlanInfo.GuaranteeRules
				.size() > 0) && !mIsAmountGuarantee && !mIsTimeGuarantee) {
			// False False 无条件强制担保订单，即必须担保
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.VISIBLE);
			mDefrayButton.setVisibility(View.GONE);
		} else if (mShowLatestarrival.contains("担保")) {
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.VISIBLE);
			mDefrayButton.setVisibility(View.GONE);
		} else if (((mIsAmountGuarantee && !mIsTimeGuarantee) || (mIsAmountGuarantee && mIsTimeGuarantee))
				&& mCurrentRoomAmount >= mRoomAmount) {
			// danbaoString = "(需担保)";
			// 房间需要担保
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.VISIBLE);
			mDefrayButton.setVisibility(View.GONE);
		} else {
			mSubmitOrderButton.setVisibility(View.VISIBLE);
			mNextButton.setVisibility(View.GONE);
			mDefrayButton.setVisibility(View.GONE);
		}

		setTitleNavBar();

		setListener();

//		DebugLog.logI("选择的城市 : "
//				+ mApplication.mHotelSearchCondition.mSearchConditionCity.cityName);
		DebugLog.logI("SubmitOrdersActivity onCreate");
	}
	
	@Override
	protected void refreshDateUI(String showDateUIString) {
		super.refreshDateUI(showDateUIString);
		
		TextView dateTextView = (TextView) findViewById(R.id.dateTextView);
		String start = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.getStartDate(), "yyyyMMdd"),
				"MM月dd日");
		String end = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.getEndDate(), "yyyyMMdd"),
				"MM月dd日");
		dateTextView.setText("入住 " + start + "- 离店 " + end);
	}

	/**
	 * 返回显示用的Float只取后两位
	 * 
	 * @return
	 */
	private float getTotalPriceFloatShow() {
		float totalprice = getTotalPriceFloat();
		BigDecimal bd = new BigDecimal(totalprice);
		bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
		return bd.floatValue();
	}

	private void setTotalPriceFloatView() {
		float totalFloat = getTotalPriceFloatShow();

		try {
			String moneyString = "";
			if (totalFloat % 1.0 == 0) {
				moneyString = "￥" + (int) (totalFloat);
			} else {
				moneyString = "￥" + totalFloat;
			}
			SpannableStringBuilder moneySpannable = new SpannableStringBuilder(
					moneyString);
			moneySpannable.setSpan(new ForegroundColorSpan(mContext
					.getResources().getColor(R.color.list_gray_text_color)), 0,
					1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			float moneySize = mContext.getResources().getDimension(
					R.dimen.list_text_small_size);
			moneySpannable.setSpan(new AbsoluteSizeSpan((int) moneySize), 0, 1,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			mMoneyTextView.setText(moneySpannable);
		} catch (Exception e) {
		}
	}

	/**
	 * 返回float上传用
	 * 
	 * @return
	 */
	private float getTotalPriceFloat() {
		float totalprice = 0F;
		try {
			totalprice = Float.parseFloat(mRatePlanInfo.TotalRate)
					* (float) mCurrentRoomAmount;
		} catch (Exception e) {
		}
		return totalprice;
	}

	/**
	 * 返回返现金总数
	 * 
	 * @return
	 */
	private int getTotalBounsInt() {
		int totalBouns = 0;
		try {
			totalBouns = (int) (Float.parseFloat(mRatePlanInfo.TotalBonus) * (float) mCurrentRoomAmount);
		} catch (Exception e) {
		}
		return totalBouns;
	}

	@Override
	protected void setListener() {
		ViewGroup topLayout = (ViewGroup) findViewById(R.id.topLayout);
		topLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				BounsDescDialog bounsDescDialog = new BounsDescDialog(mContext,
						com.android.support.jhf.R.style.DialogFromDownToUp);
				bounsDescDialog.show();
			}
		});

		mSubmitOrderButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				StringBuilder stringBuilder = new StringBuilder();
				if (checkOrderInfo(stringBuilder)) {

					CheckGuest(0);

				} else {
					HandlerToastUI.getHandlerToastUI(mContext,
							stringBuilder.toString());
				}
			}
		});
		mNextButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				StringBuilder stringBuilder = new StringBuilder();
				if (checkOrderInfo(stringBuilder)) {

					CheckGuest(1);

				} else {
					HandlerToastUI.getHandlerToastUI(mContext,
							stringBuilder.toString());
				}

			}
		});
		mDefrayButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				StringBuilder stringBuilder = new StringBuilder();
				if (checkOrderInfo(stringBuilder)) {

					CheckGuest(2);

				} else {
					HandlerToastUI.getHandlerToastUI(mContext,
							stringBuilder.toString());
				}
			}
		});

		mSubImageView = (ImageView) findViewById(R.id.subImageView);
		if (mCurrentRoomAmount == mMinBooking) {
			mSubImageView.setEnabled(false);
		}
		mAddImageView = (ImageView) findViewById(R.id.addImageView);
		int maxBooking = MAX_ROOM;
		try {
			maxBooking = Integer.parseInt(mRatePlanInfo.MaxBooking);
		} catch (Exception e) {
		}

		if (maxBooking == mCurrentRoomAmount) {
			mAddImageView.setEnabled(false);
		}
		mSubImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				mCurrentRoomAmount--;

				if (mMinBooking == mCurrentRoomAmount) {
					if (mSubImageView.isEnabled()) {
						mSubImageView.setEnabled(false);
						mAddImageView.setEnabled(true);
					}
				} else {
					if (!mSubImageView.isEnabled()) {
						mSubImageView.setEnabled(true);
					}
					if (!mAddImageView.isEnabled()) {
						mAddImageView.setEnabled(true);
					}
				}

				if (mIsPerRoomPerName) {
					// 入住人姓名下需要验证
					subLiveNameView();
				}

				modifyRoomNumber();

			}
		});
		mAddImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				int maxBooking = MAX_ROOM;
				try {
					maxBooking = Integer.parseInt(mRatePlanInfo.MaxBooking);
				} catch (Exception e) {
				}

				mCurrentRoomAmount++;

				if (mIsPerRoomPerName) {
					// 入住人姓名下需要验证
					addLiveNameView();
				}

				if (mCurrentRoomAmount == maxBooking) {
					if (mAddImageView.isEnabled()) {
						mAddImageView.setEnabled(false);
						mSubImageView.setEnabled(true);
					}
				} else {
					if (!mAddImageView.isEnabled()) {
						mAddImageView.setEnabled(true);
					}
					if (!mSubImageView.isEnabled()) {
						mSubImageView.setEnabled(true);
					}
				}

				modifyRoomNumber();

			}
		});

		mModifyRetainLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showArrivalHotelDateDialog();

			}
		});
	}

	/**
	 * 修改房间数
	 */
	private void modifyRoomNumber() {

		try {
			setTotalPriceFloatView();
			mFanTextView.setText(getTotalBounsInt() + "");
		} catch (Exception e) {
		}

		String danbaoString = "";
		if (mRatePlanInfo.PaymentType.equals("Prepay")) {
			// 预付。没有到店时间了
			mModifyRetainDivider.setVisibility(View.GONE);
			mModifyRetainLayout.setVisibility(View.GONE);
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.GONE);
			mDefrayButton.setVisibility(View.VISIBLE);
		} else if ((!"".equals(mRatePlanInfo.GuaranteeRuleIds) && mRatePlanInfo.GuaranteeRules
				.size() > 0) && !mIsAmountGuarantee && !mIsTimeGuarantee) {
			// False False 无条件强制担保订单，即必须担保
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.VISIBLE);
			mDefrayButton.setVisibility(View.GONE);
		} else if (((mIsAmountGuarantee && !mIsTimeGuarantee) || (mIsAmountGuarantee && mIsTimeGuarantee))
				&& mCurrentRoomAmount >= mRoomAmount) {
			danbaoString = "(需担保)";
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.VISIBLE);
			mDefrayButton.setVisibility(View.GONE);
		} else if (mShowLatestarrival.contains("担保")) {
			// danbaoString = "(需担保)";
			mSubmitOrderButton.setVisibility(View.GONE);
			mNextButton.setVisibility(View.VISIBLE);
			mDefrayButton.setVisibility(View.GONE);
		} else if (((mIsAmountGuarantee && !mIsTimeGuarantee) || (mIsAmountGuarantee && mIsTimeGuarantee))
				&& mCurrentRoomAmount < mRoomAmount) {
			// 不需要担保
			mSubmitOrderButton.setVisibility(View.VISIBLE);
			mNextButton.setVisibility(View.GONE);
			mDefrayButton.setVisibility(View.GONE);
			danbaoString = "";
		}
		mFangJianTextView.setText(mCurrentRoomAmount + "间" + danbaoString);

	}

	private void showArrivalHotelDateDialog() {
		final ArrivalHotelDateDialog arrivalHotelDateDialog = new ArrivalHotelDateDialog(
				mContext, com.android.support.jhf.R.style.DialogFromDownToUp,
				mArrayArrival, mRetainDateTextView.getText().toString());
		arrivalHotelDateDialog.show();
		arrivalHotelDateDialog.setOnItemListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				int position = arg2;
				String arrival = mArrayArrival.get(position);
				mLatestarrival = mUploadArrival.get(position);
				mShowLatestarrival = arrival;
				mRetainDateTextView.setText(arrival);
				if ((!"".equals(mRatePlanInfo.GuaranteeRuleIds) && mRatePlanInfo.GuaranteeRules
						.size() > 0)
						&& !mIsAmountGuarantee
						&& !mIsTimeGuarantee) {
					// False False 无条件强制担保订单，即必须担保
					mSubmitOrderButton.setVisibility(View.GONE);
					mNextButton.setVisibility(View.VISIBLE);
					mDefrayButton.setVisibility(View.GONE);
				} else if (arrival.contains("担保")) {
					// 判断日期
					mSubmitOrderButton.setVisibility(View.GONE);
					mNextButton.setVisibility(View.VISIBLE);
					mDefrayButton.setVisibility(View.GONE);
				} else if (((mIsAmountGuarantee && !mIsTimeGuarantee) || (mIsAmountGuarantee && mIsTimeGuarantee))
						&& mCurrentRoomAmount >= mRoomAmount) {
					// 判断间数
					mSubmitOrderButton.setVisibility(View.GONE);
					mNextButton.setVisibility(View.VISIBLE);
					mDefrayButton.setVisibility(View.GONE);
				} else {
					mSubmitOrderButton.setVisibility(View.VISIBLE);
					mNextButton.setVisibility(View.GONE);
					mDefrayButton.setVisibility(View.GONE);
				}

				arrivalHotelDateDialog.cancel();

			}
		});
	}

	/**
	 * 保存用户信息
	 */
	private void saveUserInfo() {
		SaveUserOperate.setLiveName(mContext, getLiveName().get(0));
		SaveUserOperate.setLivePhone(mContext, mPhoneEditTextClearView
				.getEditText().getText().toString());
	}

	private void subLiveNameView() {
		mLiveNameLayout.removeViewAt(mLiveNameLayout.getChildCount() - 1);
	}

	private void addLiveNameView() {
		View liveNameView = createLiveNameView("");
		mLiveNameLayout.addView(liveNameView);
	}

	private View createLiveNameView(String defaultLiveNameString) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.view_live_name, null);
		EditTextClearView editTextClearView = (EditTextClearView) view
				.findViewById(R.id.liveNameEditTextClearView);
		editTextClearView.getEditText().setText("");
		editTextClearView.getEditText().setSingleLine();
		editTextClearView.getEditText().setText(defaultLiveNameString);
		if (mIsNeedNationality) {
			editTextClearView.getEditText().setHint("姓名@国籍");
		} else {
			editTextClearView.getEditText().setHint("姓名");
		}
		return view;
	}

	/**
	 * 获取居住人姓名列表
	 * 
	 * @return
	 */
	private List<String> getLiveName() {
		List<String> liveNameList = new ArrayList<String>();
		for (int i = 0; i < mLiveNameLayout.getChildCount(); i++) {
			View view = mLiveNameLayout.getChildAt(i);
			EditTextClearView editTextClearView = (EditTextClearView) view
					.findViewById(R.id.liveNameEditTextClearView);
			liveNameList.add(editTextClearView.getEditText().getText()
					.toString());
		}
		return liveNameList;
	}

	@Override
	protected void setTitleNavBar() {
		TitleNavBarView titleNavBarView = (TitleNavBarView) findViewById(R.id.titleNavBarView);
		titleNavBarView.setMessage("填写订单");
		titleNavBarView.setLeftDrawableImage(R.drawable.btn_title_back);
		titleNavBarView.setLeftButtonImageString(0, "返回", R.color.text_blue);
		titleNavBarView.setLeftButtonOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				quit();
			}
		});
		titleNavBarView.setRightButtonVisibility(View.INVISIBLE);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 0: {
			// 保留时间返回
			switch (resultCode) {
			case RESULT_OK: {
				int position = data.getIntExtra("position", 0);
				String arrival = mArrayArrival.get(position);
				mLatestarrival = mUploadArrival.get(position);
				mShowLatestarrival = arrival;
				mRetainDateTextView.setText(arrival);
				if (arrival.contains("担保")) {
					mSubmitOrderButton.setVisibility(View.GONE);
					mNextButton.setVisibility(View.VISIBLE);
					mDefrayButton.setVisibility(View.GONE);
				}
				break;
			}
			case RESULT_CANCELED: {

				break;
			}
			default:
				break;
			}
			break;
		}
		case 1: {
			// 调用通讯录返回
			switch (resultCode) {
			case RESULT_OK: {
				final Map<String, List<String>> map = AppJump.contactsResult(
						SubmitOrdersActivity.this, data);
				final String nameString = map.keySet().toArray(new String[] {})[0];
				if (map.get(nameString).size() > 1) {

					showPhoneSelectDialog(nameString, map.get(nameString));

				} else {
					mPhoneEditTextClearView.getEditText().setText(
							map.get(nameString).get(0));
				}
				break;
			}
			case RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
		}
		default:
			break;
		}
	}

	private void showPhoneSelectDialog(String nameString, List<String> phoneList) {
		CustomListDialog customListDialog = CustomListDialog
				.getCustomListDialog(mContext,
						com.android.support.jhf.R.style.DialogFromDownToUp);
		final List<CustomListDialogItem> customListDialogItems = new ArrayList<CustomListDialog.CustomListDialogItem>();
		for (int i = 0; i < phoneList.size(); i++) {
			CustomListDialogItem customListDialogItem = new CustomListDialogItem();
			customListDialogItem.text = phoneList.get(i);
			customListDialogItem.textColor = getResources().getColor(
					R.color.btn_bg_blue);
			customListDialogItem.textSize = 18;
			customListDialogItems.add(customListDialogItem);
		}

		customListDialog.setMessage(customListDialogItems);
		customListDialog.setTitle(nameString);
		customListDialog.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				CustomListDialogItem customListDialogItem = customListDialogItems
						.get(arg2);
				mPhoneEditTextClearView.getEditText().setText(
						customListDialogItem.text);
			}
		});
		customListDialog.show();
	}

	private boolean checkOrderInfo(StringBuilder stringBuilder) {
		stringBuilder.delete(0, stringBuilder.length());
		List<String> liveNameList = getLiveName();
		for (int i = 0; i < liveNameList.size(); i++) {
			if (TextUtils.isEmpty(liveNameList.get(i))) {
				stringBuilder.append("请填写入住人姓名");
				return false;
			}
		}
		if (TextUtils.isEmpty(mPhoneEditTextClearView.getEditText().getText()
				.toString())) {
			stringBuilder.append("请填写联系人手机号码");
			return false;
		} else if (!ValidateOperator.isPhoneNumberValid(mPhoneEditTextClearView
				.getEditText().getText().toString())) {
			stringBuilder.append("请输入正确的手机号码");
			return false;
		}

		return true;
	}

	/**
	 * 获取endtime
	 * 
	 * @return
	 */
	private String getEndTime(String soureEndTime) {
		String endTimeString = soureEndTime;
		try {
			endTimeString = DateUtils.dateFormat(soureEndTime, "次日HH:mm",
					"HH:mm");
		} catch (Exception e) {
		}
		return endTimeString;
	}

	private void setRatePlanInfo(RatePlanInfo ratePlanInfo) {
		// 昨天时间
		Calendar yesterdayCalendar = Calendar.getInstance();
		yesterdayCalendar.setTimeInMillis(System.currentTimeMillis());
		yesterdayCalendar.add(Calendar.DAY_OF_MONTH, -1);
		String yesterdayString = DateUtils.dateFormat(
				yesterdayCalendar.getTimeInMillis(), "yyyy-MM-dd");

		// 当前时间
		String currentDate = DateUtils.getCurrentDate("yyyy-MM-dd");
		String currentHHmm = DateUtils.getCurrentDate("HH:mm");
		Calendar currentCalendar = Calendar.getInstance();
		currentCalendar.setTimeInMillis(DateUtils.getDateMillis(currentHHmm,
				"HH:mm"));
		// 当期HH:mm时间加一小时
		currentCalendar.add(Calendar.HOUR_OF_DAY, 1);

		if (!"".equals(ratePlanInfo.GuaranteeRuleIds)
				&& ratePlanInfo.GuaranteeRules.size() > 0) {
			DebugLog.logI("需要担保");
			GuaranteeRuleInfo info = ratePlanInfo.GuaranteeRules.get(0);
			if ("false".equalsIgnoreCase(info.IsTimeGuarantee)) {
				mIsTimeGuarantee = false;
			} else {
				mIsTimeGuarantee = true;
			}
			if ("false".equalsIgnoreCase(info.IsAmountGuarantee)) {
				mIsAmountGuarantee = false;
			} else {
				mIsAmountGuarantee = true;
			}

			if (mIsAmountGuarantee) {
				try {
					mRoomAmount = Integer.parseInt(info.Amount);
				} catch (Exception e) {
				}
			}

			// 入住时间和当前时间的年月日相比较看是否是今天
			String startDate = mApplication.mHotelSearchCondition
					.getStartDateFormat("yyyy-MM-dd");

			if (currentDate.equals(startDate)) {
				DebugLog.logI("当前日期");
				// 是当日
				Calendar startCalendar = Calendar.getInstance();
				startCalendar.setTimeInMillis(DateUtils.getDateMillis(
						info.StartTime, "HH:mm"));
				if (mIsTimeGuarantee) {
					DebugLog.logI("时间担保");
					// a > b
					if (currentCalendar.compareTo(startCalendar) >= 0) {
						mArrayArrival.add(info.EndTime + "以前(需担保)");
						String endTimeString = getEndTime(info.EndTime);
						mUploadArrival.add(endTimeString);
					} else {
						mArrayArrival.add(info.StartTime + "以前");
						mArrayArrival.add(info.EndTime + "以前(需担保)");

						mUploadArrival.add(info.StartTime);
						String endTimeString = getEndTime(info.EndTime);
						mUploadArrival.add(endTimeString);
					}
				} else {
					DebugLog.logI("不需要时间担保");
					Calendar temp20Calendar = Calendar.getInstance();
					temp20Calendar.setTimeInMillis(DateUtils.getDateMillis(
							"20:00", "HH:mm"));
					Calendar temp24Calendar = Calendar.getInstance();
					temp24Calendar.setTimeInMillis(DateUtils.getDateMillis(
							"24:00", "HH:mm"));
					if (currentCalendar.compareTo(temp20Calendar) >= 0) {
						DebugLog.logI("20点以后");
						if (!mIsAmountGuarantee) {
							if (currentCalendar.compareTo(temp24Calendar) >= 0) {
								// mArrayArrival.add("24:00以前(需担保)");
								mArrayArrival.add("次日6:00以前(需担保)");

								// mUploadArrival.add("24:00");
								mUploadArrival.add("6:00");
							} else {
								mArrayArrival.add("24:00以前(需担保)");
								mArrayArrival.add("次日6:00以前(需担保)");

								mUploadArrival.add("24:00");
								mUploadArrival.add("6:00");
							}
						} else {
							if (currentCalendar.compareTo(temp24Calendar) >= 0) {
								// mArrayArrival.add("24:00以前");
								mArrayArrival.add("次日6:00以前");

								// mUploadArrival.add("24:00");
								mUploadArrival.add("6:00");
							} else {
								mArrayArrival.add("24:00以前");
								mArrayArrival.add("次日6:00以前");

								mUploadArrival.add("24:00");
								mUploadArrival.add("6:00");
							}
						}
					} else {
						DebugLog.logI("20点之前");
						if (!mIsAmountGuarantee) {
							mArrayArrival.add("20:00以前(需担保)");
							mArrayArrival.add("24:00以前(需担保)");
							mArrayArrival.add("次日6:00以前(需担保)");

							mUploadArrival.add("20:00");
							mUploadArrival.add("24:00");
							mUploadArrival.add("6:00");
						} else {
							mArrayArrival.add("20:00以前");
							mArrayArrival.add("24:00以前");
							mArrayArrival.add("次日6:00以前");

							mUploadArrival.add("20:00");
							mUploadArrival.add("24:00");
							mUploadArrival.add("6:00");
						}
					}
				}
			}
			// 早上6点之前预定,昨天时间
			else if (yesterdayString.equals(mApplication.mHotelSearchCondition
					.getStartDateFormat("yyyy-MM-dd"))) {
				DebugLog.logI("昨天");
				if (mIsTimeGuarantee) {
					mArrayArrival.add("次日6:00以前(需担保)");

					mUploadArrival.add("6:00");
				} else {
					if (!mIsAmountGuarantee) {
						mArrayArrival.add("次日6:00以前(需担保)");

						mUploadArrival.add("6:00");
					} else {
						mArrayArrival.add("次日6:00以前");

						mUploadArrival.add("6:00");
					}
				}
			} else {
				DebugLog.logI("其他时间");
				if (mIsTimeGuarantee) {
					mArrayArrival.add(info.StartTime + "以前");
					mArrayArrival.add(info.EndTime + "以前(需担保)");

					mUploadArrival.add(info.StartTime);
					String endTimeString = getEndTime(info.EndTime);
					mUploadArrival.add(endTimeString);
				} else {
					if (!mIsAmountGuarantee) {
						mArrayArrival.add("20:00以前(需担保)");
						mArrayArrival.add("24:00以前(需担保)");
						mArrayArrival.add("次日6:00以前(需担保)");

						mUploadArrival.add("20:00");
						mUploadArrival.add("24:00");
						mUploadArrival.add("6:00");
					} else {
						mArrayArrival.add("20:00以前");
						mArrayArrival.add("24:00以前");
						mArrayArrival.add("次日6:00以前");

						mUploadArrival.add("20:00");
						mUploadArrival.add("24:00");
						mUploadArrival.add("6:00");
					}
				}
			}

		} else {
			DebugLog.logI("没有担保");
			String startDate = mApplication.mHotelSearchCondition
					.getStartDateFormat("yyyy-MM-dd");

			if (currentDate.equals(startDate)) {
				DebugLog.logI("当前时间");
				Calendar temp20Calendar = Calendar.getInstance();
				temp20Calendar.setTimeInMillis(DateUtils.getDateMillis("20:00",
						"HH:mm"));
				Calendar temp24Calendar = Calendar.getInstance();
				temp24Calendar.setTimeInMillis(DateUtils.getDateMillis("24:00",
						"HH:mm"));
				// DebugLog.logI("temp20Calendar : " +
				// DateUtils.dateFormat(temp20Calendar.getTimeInMillis(),
				// "yyyy-MM-dd HH:mm"));
				// DebugLog.logI("currentCalendar : " +
				// DateUtils.dateFormat(currentCalendar.getTimeInMillis(),
				// "yyyy-MM-dd HH:mm"));
				if (currentCalendar.compareTo(temp20Calendar) >= 0) {
					if (currentCalendar.compareTo(temp24Calendar) >= 0) {
						// mArrayArrival.add("24:00以前");
						mArrayArrival.add("次日6:00以前");

						// mUploadArrival.add("24:00");
						mUploadArrival.add("6:00");
					} else {
						mArrayArrival.add("24:00以前");
						mArrayArrival.add("次日6:00以前");

						mUploadArrival.add("24:00");
						mUploadArrival.add("6:00");
					}
				} else {
					mArrayArrival.add("20:00以前");
					mArrayArrival.add("24:00以前");
					mArrayArrival.add("次日6:00以前");

					mUploadArrival.add("20:00");
					mUploadArrival.add("24:00");
					mUploadArrival.add("6:00");
				}
			} else if (yesterdayString
					.equals(mApplication.mHotelSearchCondition
							.getStartDateFormat("yyyy-MM-dd"))) {
				DebugLog.logI("昨天时间");
				mArrayArrival.add("次日6:00以前");

				mUploadArrival.add("6:00");
			} else {
				DebugLog.logI("其他日期");
				mArrayArrival.add("20:00以前");
				mArrayArrival.add("24:00以前");
				mArrayArrival.add("次日6:00以前");

				mUploadArrival.add("20:00");
				mUploadArrival.add("24:00");
				mUploadArrival.add("6:00");
			}

		}

		// 设置最晚到店时间
		mLatestarrival = mUploadArrival.get(0);
		mShowLatestarrival = mArrayArrival.get(0);

		if (0 != ratePlanInfo.BookingRules.size()) {
			for (BookingRuleInfo info : ratePlanInfo.BookingRules) {
				if (info.TypeCode.equals("PerRoomPerName")) {
					mIsPerRoomPerName = true;
					// 您预订了N间房，请您提供不少于N的入住客人姓名 前台判断
				}

				if (info.TypeCode.equals("NeedNationality")) {
					// 务必提供客人国籍格式：姓名@国籍
					mRuleDescriptionTextView.setVisibility(View.VISIBLE);
					mRuleDescriptionTextView.setText(info.Description + " "
							+ "填写入住人格式：姓名@国籍");
					mIsNeedNationality = true;
				}

				if (info.TypeCode.equals("ForeignerNeedEnName")) {
					// 此酒店要求外宾务必留英文拼写 后台展示
					// _isForeignerNeedEnName = YES;
					// _needEnNameDescription = info.Description;
				}
			}
		}

		if (0 != ratePlanInfo.PrepayRules.size()) {
			PrepayRuleInfo info = ratePlanInfo.PrepayRules.get(0);
			mRuleDescriptionTextView.setVisibility(View.VISIBLE);
			mRuleDescriptionTextView.setText(info.Description);
		}
	}

	private void createOrders() {
		SubmitOrderParam submitOrderParam = new SubmitOrderParam();
		submitOrderParam.hotelid = mHotelDocs.hotelId;
		submitOrderParam.roomid = mRatePlanInfo.RoomTypeId;
		submitOrderParam.rpid = mRatePlanInfo.RateId;
		submitOrderParam.hotelname = mHotelDocs.hotelName;
		submitOrderParam.roomname = mRatePlanInfo.RoomName;
		submitOrderParam.ratename = mRatePlanInfo.RateName;
		String starttime = "";
		String endtime = "";
		if (!"".equals(mRatePlanInfo.GuaranteeRuleIds)
				&& mRatePlanInfo.GuaranteeRules.size() > 0) {
			GuaranteeRuleInfo info = mRatePlanInfo.GuaranteeRules.get(0);
			starttime = info.StartTime;
			String endTimeString = info.EndTime;
			try {
				endTimeString = DateUtils.dateFormat(endTimeString, "次日HH:mm",
						"HH:mm");
			} catch (Exception e) {
			}
			endtime = endTimeString;
		}
		submitOrderParam.starttime = starttime;
		submitOrderParam.endtime = endtime;
		submitOrderParam.roomnum = mCurrentRoomAmount + "";
		submitOrderParam.customertype = mRatePlanInfo.CustomerType;
		String paymentType = ""; // Prepay","Selfpay"
		if (mRatePlanInfo.PaymentType.equalsIgnoreCase("PrePay")) {
			paymentType = "Prepay";
		} else if (mRatePlanInfo.PaymentType.equalsIgnoreCase("SelfPay")) {
			paymentType = "Selfpay";
		}
		submitOrderParam.paymenttype = paymentType;
		float totalprice = 0;
		try {
			totalprice = getTotalPriceFloat();
		} catch (Exception e) {
		}
		submitOrderParam.totalprice = totalprice + "";
		submitOrderParam.startdate = mApplication.mHotelSearchCondition
				.getStartDate();
		submitOrderParam.enddate = mApplication.mHotelSearchCondition
				.getEndDate();
		submitOrderParam.earlyarrival = "";
		submitOrderParam.latestarrival = mLatestarrival;
		StringBuilder customer = new StringBuilder();
		List<String> liveNameList = getLiveName();
		for (int i = 0; i < liveNameList.size(); i++) {
			if (mIsNeedNationality) {
				// 需要填写姓名的时候需要国籍：姓名@国籍
				String nameString = liveNameList.get(i);
				if (!nameString.contains("@")) {
					HandlerToastUI.getHandlerToastUI(mContext,
							"请在名字后面填写国籍：姓名@国籍");
					return;
				}
			} else {
				customer.append(liveNameList.get(i)).append(",");
			}
		}
		customer.delete(customer.length() - 1, customer.length());
		submitOrderParam.customer = customer.toString();
		submitOrderParam.mobile = mPhoneEditTextClearView.getEditText()
				.getText().toString();
		submitOrderParam.needcreditcard = "";
		submitOrderParam.crednum = "";
		submitOrderParam.cvv = "";
		submitOrderParam.expyear = "";
		submitOrderParam.expmonth = "";
		submitOrderParam.holdername = "";
		submitOrderParam.idtype = "";
		submitOrderParam.idno = "";
		submitOrderParam.needinvoice = "";
		submitOrderParam.invoicetitle = "";
		submitOrderParam.invoicetype = "";
		submitOrderParam.province = "";
		submitOrderParam.city = "";
		submitOrderParam.area = "";
		submitOrderParam.invoiceaddress = "";
		submitOrderParam.invoicename = "";
		submitOrderParam.invoicemobile = "";
		submitOrderParam.userscore = "";
		submitOrderParam.bouns = Integer.parseInt(mRatePlanInfo.Bonus) + "";
		submitOrderParam.totalbouns = getTotalBounsInt() + "";
		submitOrderParam.paymentmothd = "";
		submitOrderParam.paymentmothds = "";
		// 担保类型 0不担保 1时间担保 2全天担保
		String guaranteeType = "";
		boolean guarantee = false;
		if ((!TextUtils.isEmpty(mRatePlanInfo.GuaranteeRuleIds) && mRatePlanInfo.GuaranteeRules
				.size() > 0)) {
			if (!mIsAmountGuarantee && !mIsTimeGuarantee) {
				guarantee = true;
			} else {
				// if (mLatestarrival.contains("担保")
				if (mShowLatestarrival.contains("担保")
						|| (mIsAmountGuarantee && mCurrentRoomAmount >= mRoomAmount)) {
					guarantee = true;
				}
			}
		}
		if (guarantee) {
			guaranteeType = (!mIsAmountGuarantee && !mIsTimeGuarantee) ? "2"
					: "1";
		} else {
			guaranteeType = "0";
		}

		submitOrderParam.guaranteeType = guaranteeType;

		NetworkClient.getNetworkClient().PostRequest(
				new CreateOrderRequest(mContext, submitOrderParam),
				new CreateOrderResponse() {
					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {
						if (1 == status) {
							HandlerPostUI.getHandlerPostUI(new Runnable() {

								@Override
								public void run() {
									// 提交订单
									MobclickAgent.onEvent(mContext,
											"Submit_Order");
									showDialog();
								}
							});
						} else if (0 == status) {
							HandlerToastUI.getHandlerToastUI(mContext,
									resultTextString);
						}
					}
				});

	}

	/**
	 * 核对用户填写的名字是否正确
	 * 
	 * @param type
	 *            0提交订单，1下一步担保，2支付
	 */
	private void CheckGuest(final int type) {
		boolean isgangao = false;
		if ("3201"
				.equals(mApplication.mHotelSearchCondition.mSearchConditionCity.cityId)
				|| "3301"
						.equals(mApplication.mHotelSearchCondition.mSearchConditionCity.cityId)) {
			// 是香港或者澳门
			isgangao = true;
		}
		StringBuilder customer = new StringBuilder();
		final List<String> liveNameList = getLiveName();
		for (int i = liveNameList.size() - 1; i >= 0; i--) {
			if (mIsNeedNationality) {
				// 需要填写姓名的时候需要国籍：姓名@国籍
				String nameString = liveNameList.get(i);
				if (!nameString.contains("@")) {
					HandlerToastUI.getHandlerToastUI(mContext,
							"请在名字后面填写国籍：姓名@国籍");
					return;
				}else {
					String tempLiveName = liveNameList.get(i);
					tempLiveName = tempLiveName.substring(0, tempLiveName.indexOf("@"));
					customer.append(tempLiveName).append(",");
				}
			} else {
				customer.append(liveNameList.get(i)).append(",");
			}
		}
		customer.delete(customer.length() - 1, customer.length());
		NetworkClient.getNetworkClient().PostRequest(
				new CheckGuestRequest(mContext, customer.toString(), isgangao
						+ ""), new CheckGuestResponse() {
					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {
						if ("0".equals(code)) {
							for (int i = 0; i < liveNameList.size(); i++) {
								String liveNameString = liveNameList.get(i);
								reslut = reslut.replace(liveNameString, "["
										+ liveNameString + "]");
							}
							HandlerToastUI.getHandlerToastUI(mContext, reslut, Toast.LENGTH_LONG);
						} else if ("1".equals(code)) {
							// 核对成功
							switch (type) {
							case 0: {
								// 提交订单
								saveUserInfo();

								createOrders();
								break;
							}
							case 1: {
								// 下一步担保
								saveUserInfo();

								String currentRoomAmoount = mCurrentRoomAmount
										+ "";
								String latestarrival = mLatestarrival;
								String showLatestarrival = mShowLatestarrival;
								ArrayList<String> liveNameArrayList = (ArrayList<String>) getLiveName();

								for (int i = 0; i < liveNameArrayList.size(); i++) {
									if (mIsNeedNationality) {
										// 需要填写姓名的时候需要国籍：姓名@国籍
										String nameString = liveNameArrayList
												.get(i);
										nameString = nameString.replace("﹫",
												"@");
										if (!nameString.contains("@")) {
											HandlerToastUI.getHandlerToastUI(
													mContext,
													"请在名字后面填写国籍：姓名@国籍");
											return;
										}
									} else {
									}
								}

								String phoneString = mPhoneEditTextClearView
										.getEditText().getText().toString();
								String totalprice = "";
								String totalbouns = "";
								String bouns = "";
								try {
									totalprice = getTotalPriceFloat() + "";
									bouns = Integer
											.parseInt(mRatePlanInfo.Bonus) + "";
									totalbouns = getTotalBounsInt() + "";
								} catch (Exception e) {
								}

								Intent intent = new Intent(mContext,
										CreditGuaranteesActivity.class);
								intent.putExtra("RatePlanInfo", mRatePlanInfo);
								intent.putExtra("HotelDocs", mHotelDocs);
								intent.putExtra("totalprice", totalprice);
								intent.putExtra("bouns", bouns);
								intent.putExtra("totalbouns", totalbouns);
								intent.putExtra("phoneString", phoneString);
								intent.putStringArrayListExtra(
										"liveNameArrayList", liveNameArrayList);
								intent.putExtra("currentRoomAmoount",
										currentRoomAmoount);
								intent.putExtra("latestarrival", latestarrival);
								intent.putExtra("showLatestarrival",
										showLatestarrival);
								intent.putExtra("IsTimeGuarantee",
										mIsTimeGuarantee);
								intent.putExtra("IsAmountGuarantee",
										mIsAmountGuarantee);
								intent.putExtra("title", "信用卡担保");
								intent.putExtra("tips", "担保金额");
								startActivity(intent);
								break;
							}
							case 2: {
								// 支付
								saveUserInfo();

								String currentRoomAmoount = mCurrentRoomAmount
										+ "";
								String latestarrival = mLatestarrival;
								String showLatestarrival = mShowLatestarrival;
								ArrayList<String> liveNameArrayList = (ArrayList<String>) getLiveName();

								for (int i = 0; i < liveNameArrayList.size(); i++) {
									if (mIsNeedNationality) {
										// 需要填写姓名的时候需要国籍：姓名@国籍
										String nameString = liveNameArrayList
												.get(i);
										if (!nameString.contains("@")) {
											HandlerToastUI.getHandlerToastUI(
													mContext,
													"请在名字后面填写国籍：姓名@国籍");
											return;
										}
									} else {
									}
								}

								String phoneString = mPhoneEditTextClearView
										.getEditText().getText().toString();
								String totalprice = "";
								String totalbouns = "";
								String bouns = "";
								try {
									totalprice = getTotalPriceFloat() + "";
									bouns = Integer
											.parseInt(mRatePlanInfo.Bonus) + "";
									totalbouns = getTotalBounsInt() + "";
								} catch (Exception e) {
								}

								Intent intent = new Intent(mContext,
										PaymentActivity.class);
								intent.putExtra("RatePlanInfo", mRatePlanInfo);
								intent.putExtra("HotelDocs", mHotelDocs);
								intent.putExtra("totalprice", totalprice);
								intent.putExtra("bouns", bouns);
								intent.putExtra("totalbouns", totalbouns);
								intent.putExtra("phoneString", phoneString);
								intent.putStringArrayListExtra(
										"liveNameArrayList", liveNameArrayList);
								intent.putExtra("showLatestarrival",
										showLatestarrival);
								intent.putExtra("currentRoomAmoount",
										currentRoomAmoount);
								intent.putExtra("latestarrival", latestarrival);
								intent.putExtra("IsTimeGuarantee",
										mIsTimeGuarantee);
								intent.putExtra("IsAmountGuarantee",
										mIsAmountGuarantee);
								startActivity(intent);
								break;
							}
							default:
								break;
							}
						}
					}
				});
	}

	private void showDialog() {
		CustomAlertDialog customAlertDialog = new CustomAlertDialog(mContext,
				R.style.CustomAlertDialog);
		customAlertDialog.setMessage("提交成功");
		customAlertDialog.setLeftButton("查看订单", new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(mContext, OrdersActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}
		});
		customAlertDialog.setCancelable(false);
		customAlertDialog.setCanceledOnTouchOutside(false);
		customAlertDialog.setRightButtonGone();
		customAlertDialog.show();
	}

	private void quit() {
		saveUserInfo();

		finish();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			quit();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		outState.putSerializable("ratePlanInfo", mRatePlanInfo);
		outState.putSerializable("hotelDocs", mHotelDocs);
		super.onSaveInstanceState(outState);
	}
	
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		if(null != savedInstanceState){
			
			mRatePlanInfo = (RatePlanInfo) savedInstanceState.getSerializable(
					"ratePlanInfo");
			mHotelDocs = (HotelDocs) savedInstanceState.getSerializable("hotelDocs");
			
			mLiveNameLayout = (ViewGroup) findViewById(R.id.liveNameLayout);
			mLiveNameLayout.removeAllViews();
			try {
				mMinBooking = Integer.parseInt(mRatePlanInfo.MinBooking);
			} catch (Exception e) {
			}
			// mMinBooking = 3;
			mCurrentRoomAmount = mMinBooking;
			for (int i = 0; i < mMinBooking; i++) {
				// 创建最少房间数
				if (0 == i) {
					mLiveNameLayout.addView(createLiveNameView(SaveUserOperate
							.getLiveName(mContext)));
				} else {
					if (mIsPerRoomPerName) {
						mLiveNameLayout.addView(createLiveNameView(""));
					}
				}
			}
		}
		DebugLog.logI("SubmitOrdersActivity onRestoreInstanceState");
	}
}
